<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Order extends Model
{
    /**
     * 表名称
     * @var $table;
     */
    protected $table = 'order';

    /**
     * 主键
     * @var $primaryKey
     */
    protected $primaryKey = 'order_id';

    /**
     * 时间戳   laravel ORM 自动维护数据库时间戳,用户数据结构的回滚操作,默认开启,我们禁止
     * @var bool $timestamps
     */
    public $timestamps = false;

    use SoftDeletes;

    protected $dates = ['deleted_at'];
    /**
     * 自动填充字段
     * @var $fillable
     */

    protected $fillable = [
                                'order_sn',
                                'user_id',
                                'coupon_id',
                                'add_time',
                                'order_status',
                                'order_type',
                                'shop_id',
                                'order_price',
                                'shipping_fee',
                                'order_tariff_fee',
                                'total_goods_number',
                                'pay_price',
                                'discount_price',
                                'order_pay_id',
                                'country',
                                'province',
                                'city',
                                'district',
                                'address',
                                'consignee',
                                'mobile',
                                'id_type',
                                'id_card',
                                'invoice_message',
                                'order_message',
                                'deleted_at',
                                'shipping_type',
                                'shipping_num',
                                'shipping_time',
                                'shipping_message',
                                'push_tarrif',
                                'push_tarrif_time',
                                'recive_goods_time',
                                'cancel_reason',
                                'cancel_time',
                                'is_remind',
                                'pay_type',
                                'pay_num',
                                'pay_time',
                                'pay_push',
                                'pay_push_success_time',
                                'create_order_device',
                        ];


    public function getPayLeftTimeAttribute(){ 

        $addTime = $this->getAttribute('add_time');
        $limitTime = config('order-setting.order-cancel-time');
        $passedTime = time()-strtotime($addTime);
        $leftTime = $limitTime-$passedTime;
        return $leftTime<0?0:$leftTime;

    }
}
